<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="6">
        <div class="grid-content">
          <p>可用余额（元）</p>
          <h2>20.00</h2>
          <el-button type="primary" class="btn" @click="dialogVisible = true"
            >申请提现</el-button
          >
        </div>
      </el-col>
      <el-col :span="6">
        <div class="grid-content">
          <p>累计收入（元）</p>
          <h2>20.00</h2>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="grid-content">
          <p>待结算金额（元）</p>
          <h2>21</h2>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="grid-content">
          <p>冻结金额（元）</p>
          <h2>20.00</h2>
        </div>
      </el-col>
    </el-row>

    <el-table
      ref="multipleTable"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column label="交易时间" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.created_time }}</span>
        </template>
      </el-table-column>
      <el-table-column label="提款账户" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.account }}</span>
        </template>
      </el-table-column>
      <el-table-column label="开户人" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="提现金额" align="center">
        <template slot-scope="{ row }">
          <span>￥{{ row.price }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center">
        <template slot-scope="{ row }">
          <el-tag :type="row.status | statusFilter">
            {{ row.status | statusFilterContent }}
          </el-tag>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="page"
      @pagination="getCashconfirmList"
    />

    <el-dialog title="提现" :visible.sync="dialogVisible" width="30%">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
      >
        <el-form-item label="提现金额" prop="price">
          <el-input-number v-model="ruleForm.price"></el-input-number>
        </el-form-item>
        <el-form-item label="提现账户">
          <el-select v-model="ruleForm.region" placeholder="请选择">
            <el-option
              label="中国银行6216**********7287"
              value="6216**********7287"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="saveCashconfirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getCashconfirmList, saveCashconfirm } from "@/api/assets";
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination

export default {
  components: { Pagination },
  data() {
    return {
      page: 1,
      total: 0,
      list: [],
      ruleForm: {
        price: 0,
        region: ""
      },
      dialogVisible: false,
      rules: {},
      cash_id: 1
    };
  },
  created() {
    this.getCashconfirmList();
  },
  methods: {
    // 申请提现列表
    async getCashconfirmList() {
      const {
        code,
        data: { total, items }
      } = await getCashconfirmList(this.page);
      if (code == 20000) {
        (this.list = items), (this.total = total);
      }
    },
    // 申请提现
    async saveCashconfirm() {
      const { code, data } = await saveCashconfirm(
        this.cash_id,
        this.ruleForm.price
      );
      if (code == 20000) {
        this.dialogVisible = false;
        this.$notify({
          title: "Success",
          message: "申请成功，等待审核",
          type: "success"
        });
        this.getCashconfirmList();
      }
    }
  },
  filters: {
    statusFilter(status) {
      const statusMap = {
        0: "danger",
        1: "success"
      };
      return statusMap[status];
    },
    statusFilterContent(status) {
      const statusMap = {
        0: "审核中",
        1: "已审核"
      };
      return statusMap[status];
    },
    typeFilter(type) {
      return calendarTypeKeyValue[type];
    }
  }
};
</script>

<style lang="scss" scoped>
.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}
.grid-content {
  position: relative;
  border-radius: 4px;
  min-height: 36px;
  border: 1px solid #e6ebf5;
  p,
  h2 {
    margin: 0;
    padding-left: 20px;
    padding: 20px 20px 20px;
  }
  p {
    border-bottom: 1px solid #e6ebf5;
  }
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
.btn {
  position: absolute;
  top: 20px;
  right: 20px;
}
</style>
